package com.ruoyi.system.api.config;

import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.TokenConstants;
import com.ruoyi.common.core.utils.JwtUtils;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;

/**
 * 客户端配置 - 自定义请求头
 *
 */
@Configuration
public class FeignConfig implements RequestInterceptor {
    private String toke = "";

    public FeignConfig() {
        // TODO 使用任务用户作为message处理用户
        Map<String, Object> claimsMap = new HashMap<String, Object>();
        claimsMap.put(SecurityConstants.USER_KEY, "00000000-0000-0000-0000-000000000000");
        claimsMap.put(SecurityConstants.DETAILS_USER_ID, 1L);
        claimsMap.put(SecurityConstants.DETAILS_USERNAME, "admin");
        this.toke = JwtUtils.createToken(claimsMap);
    }

    /**
     * 添加一个token, 用于获取权限
     *
     * @param requestTemplate
     */
    @Override
    public void apply(RequestTemplate requestTemplate) {
        requestTemplate.header(TokenConstants.AUTHENTICATION, this.toke);
    }
}